
package com.joolun.cloud.mall.api.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.joolun.cloud.mall.api.mapper.UserRecordMapper;
import com.joolun.cloud.mall.api.service.UserRecordService;
import com.joolun.cloud.mall.common.entity.UserRecord;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;

/**
 * 用户消费记录
 *
 * @author www.joolun.com
 * @date 2021-04-22 11:18:16
 */
@Service
public class UserRecordServiceImpl extends ServiceImpl<UserRecordMapper, UserRecord> implements UserRecordService {

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateTotalOrder(String userId, Integer num) {
		baseMapper.update(new UserRecord(), Wrappers.<UserRecord>lambdaUpdate()
				.eq(UserRecord::getUserId, userId)
				.setSql(" total_order = total_order + " + num));
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateTotalAmount(String userId, BigDecimal num) {
		baseMapper.update(new UserRecord(), Wrappers.<UserRecord>lambdaUpdate()
				.eq(UserRecord::getUserId, userId)
				.setSql(" total_amount = total_amount + " + num));
	}
}
